package com.hm.manage.utils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.util.UriComponentsBuilder;

@Slf4j
@Component
public class SmsHttp2Service {

    //@Value("${sms.url}")
    private  String smsUrl = "http://50.58.187.80:50001/v2sms.aspx";
    @Value("${sms.userid}")
    private  String userId;
    @Value("${sms.account}")
    private  String account;
    @Value("${sms.password}")
    private  String password;
    @Value("${sms.action}")
    private  String action;

    public String sendSms(String mobile, String content)  {
        // 构建请求URL并自动编码参数
        //String url = smsUrl+"?action="+action+"&userid="+userId+"&account="+account+"&password="+password+"&mobile="+mobile+"&content="+content;
        // 构建请求URL并自动编码参数
        String url = UriComponentsBuilder.fromHttpUrl(smsUrl)
                .queryParam("action", action)
                .queryParam("userid", userId)
                .queryParam("account", account)
                .queryParam("password", password)
                .queryParam("mobile", mobile)
                .queryParam("sendtime", "")
                .queryParam("extno", "")
                .queryParam("content", content)
                .build()
                .toUriString();


        log.info("------发送短信请求URL：{}", url);
        // 发送GET请求并获取响应
        String block = WebClient.create()
                .get()
                .uri(url)
                .retrieve()
                .bodyToMono(String.class)
                .block();
        return block;

    }



}
